<template>
<div class="come-store-add views-container">
  <div class="wlm-form">
    <div class="wlm-form-header">添加自提点</div>
    <div class="wlm-form-content">
      <el-form :ref="formFormatData.key" :model="formFormatData.formData" :rules="formFormatData.rules" size="small" label-width="120px" class="retail-form" label-position="right">
        <el-form-item label="商家名称">
          <el-input v-model.trim="formFormatData.formData.status">
          </el-input>
        </el-form-item>
        <el-form-item label="自提点名称">
          <el-input v-model.trim="formFormatData.formData.status">
          </el-input>
        </el-form-item>
        <el-form-item label="自提点图片">
          <upload ref="uploadplatform" :config="platformConfig" :changeEvt="uploadPlatformChange"></upload>
          <div class="form-help">最多添加10张图片，图片大小200*200</div>
        </el-form-item>
        <el-form-item label="自提点位置" class="city" prop="address">
          <div class="flex-row flex-align-c">
            <city-select :config="{}" ref="cityselect" :changeEvt="chooseCity"></city-select>
          </div>
        </el-form-item>
        <el-form-item label="地图定位">
          <div class="flex-row flex-align-c">
            <baidu-map :changeEvt="getPoint"></baidu-map>
          </div>
        </el-form-item>
      </el-form>
    </div>
  </div>
  <div v-cloak class="wlm-fixed-btn flex-row flex-align-c flex-justify-c">
    <el-button size="small" @click="formFormatSubmit({ router: { type: 'replace', path: '/user/managementUser', code: 1 }})" type="primary">保存</el-button>
    <router-link tag="span" to="/user/managementUser">
      <el-button size="small">返回</el-button>
    </router-link>
  </div>
</div>
</template>

<script>
// import { userAdd } from '@/api/user'
import upload from '@/components/Upload/index'
import BaiduMap from '@/components/BaiduMap/index'
import CitySelect from '@/components/CitySelect/index'
import {
  userAdd
} from '@/api/user'
import {
  regPhone,
  regPassword
} from '@/utils/regular'
import mixins from '@/mixins/mixins'
export default {
  mixins: [mixins.getters('Form')],
  name: 'ComeStoreAdd',
  components: {
    upload,
    BaiduMap,
    CitySelect
  },
  directives: {

  },
  data() {
    var mobile = (rule, value, callback) => {
      if (!regPhone(value)) {
        return callback(new Error('注册手机号格式不正确'))
      } else {
        callback()
      }
    }

    var checkPwd = (rule, value, callback) => {
      if (!regPassword(value)) {
        return callback(new Error('密码格式错误'))
      } else {
        callback()
      }
    }
    var checkPass = (rule, value, callback) => {
      if (value !== this.formFormatData.formData.password) {
        return callback(new Error('两次密码输入不一致'))
      } else {
        callback()
      }
    }
    return {
      platformConfig: {
        type: ['image'],
        initList: []
      },
      formFormatData: {
        key: 'userForm',
        api: {
          // editForm
          submitForm: userAdd
        },
        formData: {
          nickname: '',
          password: '',
          repassword: '',
          username: '',
          logo: []
        },
        rules: {
          nickname: [{
            required: true,
            message: '请输入真实姓名',
            trigger: 'blur'
          }],
          password: [{
            required: true,
            message: '请输入密码',
            trigger: 'blur'
          },
          {
            validator: checkPwd,
            trigger: 'blur'
          }
          ],
          repassword: [{
            required: true,
            message: '请输入确认密码',
            trigger: 'blur'
          },
          {
            validator: checkPass,
            trigger: 'blur'
          }
          ],
          username: [{
            required: true,
            message: '请输入用户手机号',
            trigger: 'blur'
          },
          {
            validator: mobile,
            trigger: 'blur'
          }
          ]
        }
      }
    }
  },
  methods: {
    uploadPlatformChange(imgs) {

    },
    chooseCity(params) {

    },
    getPoint(params) {

    }
  }
}
</script>

<style lang="scss" scoped>
.come-store-add {}
</style>
